package com.zx.notification.admin.controller;

import com.zx.core.wrapper.ObjectWrapper;
import com.zx.core.wrapper.PageWrapper;
import com.zx.core.wrapper.ResponseWrapper;
import com.zx.log.annotation.OperateLog;
import com.zx.notification.admin.service.INotificationTemplatesService;
import com.zx.notification.common.param.NotificationTemplatesParam;
import com.zx.notification.common.vo.NotificationTemplatesVO;
import com.zx.validation.annotation.ParameterValidation;
import com.zx.validation.annotation.ParameterValidations;
import com.zx.validation.enums.ValidateRulesEnum;
import com.zx.validation.groups.Create;
import com.zx.validation.groups.StatusUpdate;
import com.zx.validation.groups.Update;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * description: 通知模板管理控制器 <br>
 * create: 2025-10-17
 * </p>
 *
 * @author zhou  xun
 */
@RestController
@RequestMapping("/notification-templates")
@RequiredArgsConstructor
public class NotificationTemplatesController {

    private final INotificationTemplatesService iNotificationTemplatesService;

    /**
     * 分页查询通知模板列表
     *
     * @param notificationTemplatesParam 查询参数
     * @return 通知模板列表
     */
    @PreAuthorize("hasAuthority('notify:template:list')")
    @PostMapping("/list")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "通知模板参数", rules = {ValidateRulesEnum.OBJECT}, groups = {com.zx.validation.groups.Query.class})
    })
    public PageWrapper<NotificationTemplatesVO> list(@RequestBody NotificationTemplatesParam notificationTemplatesParam) {
        return iNotificationTemplatesService.getNotificationTemplatesVOListByPage(notificationTemplatesParam);
    }

    /**
     * 新增通知模板
     *
     * @param notificationTemplatesParam 通知模板信息
     * @return {@link ResponseWrapper}
     */
    @PreAuthorize("hasAuthority('notify:template:add')")
    @OperateLog(value = "新增通知模板")
    @PostMapping("/addNotificationTemplate")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知模板参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Create.class})
    )
    public ResponseWrapper addNotificationTemplate(@RequestBody NotificationTemplatesParam notificationTemplatesParam) {
        return iNotificationTemplatesService.addNotificationTemplate(notificationTemplatesParam);
    }

    /**
     * 编辑通知模板
     *
     * @param notificationTemplatesParam 通知模板信息
     * @return {@link ResponseWrapper}
     */
    @PreAuthorize("hasAuthority('notify:template:edit')")
    @OperateLog(value = "编辑通知模板")
    @PutMapping("/editNotificationTemplate")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知模板参数", rules = {ValidateRulesEnum.OBJECT}, groups = {Update.class})
    )
    public ResponseWrapper editNotificationTemplate(@RequestBody NotificationTemplatesParam notificationTemplatesParam) {
        return iNotificationTemplatesService.editNotificationTemplate(notificationTemplatesParam);
    }

    /**
     * 删除通知模板
     *
     * @param notificationTemplateId 通知模板Id
     * @return {@link ResponseWrapper}
     */
    @PreAuthorize("hasAuthority('notify:template:remove')")
    @OperateLog(value = "删除通知模板")
    @DeleteMapping("/deleteNotificationTemplate/{notificationTemplateId}")
    @ParameterValidations({
            @ParameterValidation(index = 0, desc = "通知模板Id", rules = {ValidateRulesEnum.NOT_NULL})
    })
    public ResponseWrapper deleteNotificationTemplate(@PathVariable("notificationTemplateId") String notificationTemplateId) {
        return iNotificationTemplatesService.deleteNotificationTemplate(notificationTemplateId);
    }

    /**
     * 获取指定通知模板信息
     *
     * @param notificationTemplateId 通知模板Id
     * @return 通知模板信息
     */
    @PreAuthorize("hasAuthority('notify:template:detail')")
    @OperateLog(value = "获取指定通知模板信息")
    @GetMapping("/info/{notificationTemplateId}")
    public ObjectWrapper<NotificationTemplatesVO> getNotificationTemplateInfo(@PathVariable("notificationTemplateId") String notificationTemplateId) {
        return iNotificationTemplatesService.selectNotificationTemplateById(notificationTemplateId);
    }

    /**
     * 更新通知模板状态
     *
     * @param notificationTemplatesParam 通知模板参数
     * @return {@link ResponseWrapper}
     */
    @PreAuthorize("hasAuthority('notify:template:edit')")
    @OperateLog(value = "更新通知模板状态")
    @PutMapping("/updateNotificationTemplateStatus")
    @ParameterValidations(
            @ParameterValidation(index = 0, desc = "通知模板参数", rules = {ValidateRulesEnum.OBJECT}, groups = {StatusUpdate.class})
    )
    public ResponseWrapper updateNotificationTemplateStatus(@RequestBody NotificationTemplatesParam notificationTemplatesParam) {
        return iNotificationTemplatesService.updateNotificationTemplateStatus(notificationTemplatesParam);
    }
}